package com.xiaoyu.lingdian.service.impl;

import java.util.Map;
import java.util.List;
import java.util.HashMap;
import com.xiaoyu.lingdian.core.mybatis.page.Page;
import com.xiaoyu.lingdian.core.mybatis.page.PageRequest;
import com.xiaoyu.lingdian.service.CoreAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xiaoyu.lingdian.core.mybatis.dao.MyBatisDAO;
import com.xiaoyu.lingdian.entity.CoreArea;

@Service("coreAreaService")
public class CoreAreaServiceImpl implements CoreAreaService {

	@Autowired
	private MyBatisDAO myBatisDAO;

	@Override
	public boolean insertCoreArea(CoreArea coreArea) {
		myBatisDAO.insert(coreArea);
		return true;
	}

	@Override
	public boolean updateCoreArea(CoreArea coreArea) {
		myBatisDAO.update(coreArea);
		return true;
	}

	@Override
	public boolean deleteCoreArea(CoreArea coreArea) {
		myBatisDAO.delete(coreArea);
		return true;
	}

	private static final String DELETEBATCH_COREAREA_BY_IDS="deleteBatchCoreAreaByIds";
	
	@Override
	public boolean deleteBatchByIds(List<String> list ) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("list", list);
		myBatisDAO.delete(DELETEBATCH_COREAREA_BY_IDS,hashMap);
		return true;
	}

	@Override
	public CoreArea getCoreArea(CoreArea coreArea) {
		return (CoreArea) myBatisDAO.findForObject(coreArea);
	}

	private static final String FIND_COREAREA_FOR_LISTS="findCoreAreaForLists";

	@SuppressWarnings("unchecked")
	@Override
	public List<CoreArea> findCoreAreaList() {
		return myBatisDAO.findForList(FIND_COREAREA_FOR_LISTS, null);
	}
	
	private static final String FIND_COREAREA_FOR_PAGES="findCoreAreaForPages";

	@SuppressWarnings("unchecked")
	@Override
	public Page<CoreArea> findCoreAreaPage(String craraName, int pageNum, int pageSize) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("craraName", craraName);
		return myBatisDAO.findForPage(FIND_COREAREA_FOR_PAGES, new PageRequest(pageNum, pageSize, hashMap));
	}

	private static final String FIND_COREAREA_FOR_PAGES_CRARATOP="findCoreAreaForPagesByCraraTop";
	
	@SuppressWarnings("unchecked")
	@Override
	public Page<CoreArea> findCoreAreaPageByCraraTop(String craraTop, int pageNum, int pageSize) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("craraTop", craraTop);
		return myBatisDAO.findForPage(FIND_COREAREA_FOR_PAGES_CRARATOP, new PageRequest(pageNum, pageSize, hashMap));
	}
	
}